
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
      <?php
header("Content-type: text/html; charset=utf-8");

require("conn.php");
$action=@$_GET['action'];
?> 
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>管理员列表</title>
  <!--[if lt IE 9]>
  <script type="text/javascript" src="static/js/html5.js"></script>
  <script type="text/javascript" src="static/js/respond.min.js"></script>
  <![endif]-->
  <script type="text/javascript" src="static/js/jquery.min.js"></script>
  <script type="text/javascript" src="static/js/laypage.js"></script>
  <script type="text/javascript" src="static/js/layer.js"></script>
  <link rel="stylesheet" type="text/css" href="static/css/iconfont.css">
  <link href="static/css/Style.css" rel="stylesheet" type="text/css">    

	
</head>
<body>
    <div class="m_path">
        <div class="m_ptxt1">
            <div class="m_nav2" onClick="location.href='admin_manage.php';"><i class="iconfont">&#xe6a4;</i>&ensp;管理员列表</div>
            
          <!--  <div class="m_nav1" onClick="location.href='admin_role.asp';"><i class="iconfont">&#xe69d;</i>&ensp;管理员角色</div>
            -->
        </div>
        <div class="m_ptxt2"><i class="iconfont">&#xe6b8;</i>&ensp;位置：<a href="index.php" target="_top">首页</a> > 管理员列表</div>
    </div>
	<?php
	if($action=="del"){
	$id=@$_GET['id'];
	
	if($id==""){
	 echo "<script language='javascript'>alert('id不能为空！');history.go(-1)</script>";
	 return false;
	}
	if($id==1){
	 echo "<script language='javascript'>alert('默认管理员不可删除！');history.go(-1)</script>";
	 return false;
	}
		
	 $sql="delete from  admin  where id in (".$id.")";
   if (mysql_query($sql)){ 
echo "<script language='javascript'>alert('已删除！');window.location.href='admin_manage.php';</script>";
return false;
 } else{
   echo '删除失败，SQL:$sql错误：'.mysql_error();
	}
	
	
	}
	if($action=="save"){
	$id=@$_POST['id'];
	$m_name=@$_POST['m_name'];
	$m_pwd=@$_POST['m_pwd'];
	$mi=@$_POST['mi'];
	$m_vpwd=@$_POST['m_vpwd'];
	$tai=@$_POST['tai'];
      $nian=@$_POST['nian'];
    $ban=@$_POST['ban'];
	if($m_name==""){
	 echo "<script language='javascript'>alert('账号不能为空！');history.go(-1)</script>";
	 return false;
	}
	if($m_pwd!=$m_vpwd){
	 echo "<script language='javascript'>alert('两次密码需要一致！');history.go(-1)</script>";
	 return false;
	}

  if($m_pwd==$m_vpwd && !empty($m_pwd) ){
    $m_pwd=md5($m_pwd);
  }else{
     $m_pwd=$mi;
  }
    
	 $sql1="update admin  set hao='".$m_name."',mi='".$m_pwd."',nian='".$nian."',ban='".$ban."',tai=".$tai." where id=".$id."";
    if (mysql_query($sql1)){ 
	 
	  echo "<script language='javascript'>alert('修改成功！');window.location.href='admin_manage.php?lei=qq&a=reg';</script>";
	 }else{
	 echo 'no';
	 }
	 
	 
	}
	if($action=="addsave"){
	$id=@$_POST['id'];
	$m_name=@$_POST['m_name'];
	$m_pwd=@$_POST['m_pwd'];
	$mi=@$_POST['mi'];
	$m_vpwd=@$_POST['m_vpwd'];
	$tai=@$_POST['tai'];
    $nian=@$_POST['nian'];
    $ban=@$_POST['ban'];

	if($m_name==""){
	 echo "<script language='javascript'>alert('账号不能为空！');history.go(-1)</script>";
	 return false;
	}
	if($m_pwd!=$m_vpwd){
	 echo "<script language='javascript'>alert('两次密码需要一致！');history.go(-1)</script>";
	 return false;
	}
		if($m_pwd==""){
	 echo "<script language='javascript'>alert('密码不能为空！');history.go(-1)</script>";
	 return false;
	}
	$m_pwd=md5($m_pwd);
	
	$sql1="INSERT INTO admin(hao,mi,tai,nian,ban) VALUES ('".$m_name."','".$m_pwd."',".$tai.",'".$nian."','".$ban."');";

	
    if (mysql_query($sql1)){ 
	
	  echo "<script language='javascript'>alert('添加成功！');window.location.href='admin_manage.php?lei=qq&a=reg';</script>";
	  return false;
	 }else{
	 echo 'no';
	 }
	}
	if($action=="edit"){
	$id=@$_GET['id'];
	$result = @mysql_query("SELECT * FROM admin where id=".$id."");
				 $row = @mysql_fetch_array($result);
	?>
	   <div class="m_rctr">
        <div class="m_ssctt">
            <form id="myform"  name="myform" action="?action=save" method="post">
			<input name="mi" type="hidden" value="<?php echo $row["mi"];?>">
                <table width="100%" cellpadding="0" cellspacing="0">
                    <tbody><tr>
                        <td width="110" class="t-ar">用户名：</td>
                        <td>
                            <input type="text" name="m_name" id="m_name" datatype="*" nullmsg="请输入用户名!" class="input_txt" value="<?php echo $row["hao"];?>">
                            <div class="input_sm">请填写用户名</div>
                        </td>
                    </tr>
                    <tr>
                        <td class="t-ar">密码：</td>
                        <td>
                            <input type="password" name="m_pwd" id="m_pwd" class="input_txt" value="" style="width:150px;">
                            <div class="input_sm">不改请不填写</div>
                        </td>
                    </tr>
                    <tr>
                        <td class="t-ar">确认密码：</td>
                        <td>
                            <input type="password" name="m_vpwd" id="m_vpwd" class="input_txt" value="" style="width:150px;">
                            <div class="input_sm">不改请不填写</div>
                        </td>
                    </tr>
                   
                                    <tr>
                        <td class="t-ar">年级：</td>
                        <td>
                           <select name="nian" id="nian">
  <option value ="2018" <?php if ($row["nian"]=="2018") {echo "select='selected'"; } ?> >2018</option>
  <option value ="2019" <?php if ($row["nian"]=="2019") {echo "select='selected'"; } ?>>2019</option>
  <option value="2020" <?php if ($row["nian"]=="2020") {echo "select='selected'"; } ?>>2020</option>
  <option value="2021" <?php if ($row["nian"]=="2021") {echo "select='selected'"; } ?>>2021</option>
  <option value="2022" <?php if ($row["nian"]=="2022") {echo "select='selected'"; } ?>>2022</option>
  <option value="2023" <?php if ($row["nian"]=="2023") {echo "select='selected'"; } ?>>2023</option>
</select>
                         
                        </td>
                    </tr>
                                        <tr>
                        <td class="t-ar">班级：</td>
                        <td>
                                                    <select  name="ban" id="ban">
  <option value ="1">1</option>
  <option value ="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
</select>
                         
                        </td>
                    </tr>

                    <tr>
                        <td class="t-ar">用户状态：</td>
                        <td>
                            <select name="tai" class="input_select">
                                <option value="1" selected="">激活</option>
                                <option value="0">锁定</option>
                            </select>
                            <div class="input_sm"> </div>
                        </td>
                    </tr>
                    <input type="hidden" name="id" value="<?php echo $id;?>">
                    <tr>
                        <td height="55" style="border:0;">&nbsp;</td>
                        <td style="border:0;">
                            <input type="submit" class="input_btn" value="确认编辑" onMouseOver="this.className='input_btn1'" onMouseOut="this.className='input_btn'">
                            <input type="reset" class="input_btn" value="取消重置" onMouseOver="this.className='input_btn1'" onMouseOut="this.className='input_btn'">
                        </td>
                    </tr>
                </tbody></table>
            </form>
        </div>
    </div>
		<?php
	}elseif($action=="add"){
	?>
	 <div class="m_rctr">
        <div class="m_ssctt">
            <form id="myform"  name="myform" action="?action=addsave" method="post">
		
                <table width="100%" cellpadding="0" cellspacing="0">
                    <tbody><tr>
                        <td width="110" class="t-ar">用户名：</td>
                        <td>
                            <input type="text" name="m_name" id="m_name" datatype="*" nullmsg="请输入用户名!" class="input_txt" value="">
                            <div class="input_sm">请填写用户名</div>
                        </td>
                    </tr>
                    <tr>
                        <td class="t-ar">密码：</td>
                        <td>
                            <input type="password" name="m_pwd" id="m_pwd" class="input_txt" value="" style="width:150px;">
                            
                        </td>
                    </tr>
                    <tr>
                        <td class="t-ar">确认密码：</td>
                        <td>
                            <input type="password" name="m_vpwd" id="m_vpwd" class="input_txt" value="" style="width:150px;">
                         
                        </td>
                    </tr>
                                       <tr>
                        <td class="t-ar">年级：</td>
                        <td>
                           <select name="nian" id="nian">
  <option value ="2018">2018</option>
  <option value ="2019">2019</option>
  <option value="2020">2020</option>
  <option value="2021">2021</option>
  <option value="2022">2022</option>
  <option value="2023">2023</option>
</select>
                         
                        </td>
                    </tr>
                                        <tr>
                        <td class="t-ar">班级：</td>
                        <td>
                                                    <select  name="ban" id="ban">
  <option value ="1">1</option>
  <option value ="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
</select>
                         
                        </td>
                    </tr>
                    <tr>
                        <td class="t-ar">用户状态：</td>
                        <td>
                            <select name="tai" class="input_select">
                                <option value="1" selected="">激活</option>
                                <option value="0">锁定</option>
                            </select>
                         
                        </td>
                    </tr>
                 
                    <tr>
                        <td height="55" style="border:0;">&nbsp;</td>
                        <td style="border:0;">
                            <input type="submit" class="input_btn" value="确认添加" onMouseOver="this.className='input_btn1'" onMouseOut="this.className='input_btn'">
                            <input type="reset" class="input_btn" value="取消重置" onMouseOver="this.className='input_btn1'" onMouseOut="this.className='input_btn'">
                        </td>
                    </tr>
                </tbody></table>
            </form>
        </div>
    </div>
	<?php
	}else{
	?>
    <div class="m_rctr">
        <form method="post" name="listform" action="?action=delall">
        <div class="m_rctt mb12">
            <table width="100%" cellpadding="0" cellspacing="0" border="1" bordercolor="#c9c9c9">
                <thead>
                    <tr>
                       <!-- <td width="6%">选择</td>-->
                        <td width="6%">编号</td>
                        <td width="15%">用户名</td>
                        <td width="15%">所属角色</td>
                        <td width="12%">用户状态</td>
                        <td>操作</td>
                    </tr>
                </thead>
                <tbody>
  <?php
				
  $Page_size=30; 

$result=mysql_query('select * from admin  '); 
$count = mysql_num_rows($result); 
$page_count = ceil($count/$Page_size); 

$init=1; 
$page_len=7; 
$max_p=$page_count; 
$pages=$page_count; 

$keys=@$_GET['keys'];
//判断当前页码 
if(empty($_GET['page'])||$_GET['page']<0){ 
$page=1; 
}else { 
$page=$_GET['page']; 
} 
$xu=@$_GET['xu'];
$offset=$Page_size*($page-1); 
$sql="select * from admin  where 1=1 "; 



if($xu==1){
$sql=$sql." order by id asc "; 

}else{
$sql=$sql." order by id asc "; 
}

$sql=$sql." limit $offset,$Page_size"; 

$result=mysql_query($sql,$conn); 
$i=1;
while ($row=mysql_fetch_array($result)) { 

if($row["tai"]==1){
$tai="正常";
}else{
$tai="冻结";
}

?>  
                    <tr onMouseOver="this.className='over';" onMouseOut="this.className='';" class="over">
                     <!--    <td><input type="checkbox" name="m_id" value="<?php echo $row["id"];?>"></td>-->
                        <td><?php echo $i;?></td>
                        <td><?php echo $row["hao"];?></td>
                        <td><span class='span1'><?php if ($row["id"] !=1 ) { echo "教师"; }else{echo "管理员"; } ?>  </span></td>
                        <td><span class='span1'><?php echo $tai;?></span></td>
                        <td>
                            <div class="btn11" onMouseOver="this.className='btn12';" onMouseOut="this.className='btn11';" onClick="location.href='?action=edit&id=<?php echo $row["id"];?>';"><i class="iconfont">&#xe761;</i>编辑</div>
                            <div class="btn21" onMouseOver="this.className='btn22';" onMouseOut="this.className='btn21';" onClick="if(!confirm('申请删除后，不可恢复！是否同意删除！') )return false;{window.location.href='?action=del&id=<?php echo $row["id"];?>';}"><i class="iconfont">&#xe6b4;</i>删除</div>                        </td>
                    </tr>
					<?php
					$i=$i+1;
	  }
	  ?>
                   
                </tbody>
            </table>
        </div>
        <div class="m_rctt">
            <div class="fl"> <!--  <div class="s_ctr"><input type="checkbox" name="chkall" onClick="checkAll(this.checked,'m_id')"></div><input type="button" class="input_btn2" value="批量删除" onMouseOver="this.className='input_btn3'" onMouseOut="this.className='input_btn2'" onClick="layer.open({btn: ['确认', '取消'],icon: 3,yes: function(index,layero){listform.submit();},content: '确认要删除吗？'});">-->
			<input type="button" class="input_btn2" style="    background-color: #3d9970 !important; color: #fff;    border-radius: 3px;" value="添加管理员" onMouseOver="this.className='input_btn3'" onMouseOut="this.className='input_btn2'" onClick="location.href='?action=add';"></div>
            <?php 

$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数 
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量 

$key=''; 

$key.="<span>共".$count3."</span>&nbsp;#"; //第几页,共几页 
$key.="<span>$page/$pages</span> "; //第几页,共几页 
if($page!=1){ 
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page=1&type=".$type."&keys=".$keys."&xu=".$xu."\">第一页</a> "; //第一页 
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."&type=".$type."&keys=".$keys."&xu=".$xu."\">上一页</a>"; //上一页 
}else { 
$key.="第一页 ";//第一页 
$key.="上一页"; //上一页 
} 
if($pages>$page_len){ 
//如果当前页小于等于左偏移 
if($page<=$pageoffset){ 
$init=1; 
$max_p = $page_len; 
}else{//如果当前页大于左偏移 
//如果当前页码右偏移超出最大分页数 
if($page+$pageoffset>=$pages+1){ 
$init = $pages-$page_len+1; 
}else{ 
//左右偏移都存在时的计算 
$init = $page-$pageoffset; 
$max_p = $page+$pageoffset; 
} 
} 
} 
for($i=$init;$i<=$max_p;$i++){ 
if($i==$page){ 
$key.=' <span>'.$i.'</span>'; 
} else { 
$key.=" <a  href=\"".$_SERVER['PHP_SELF']."?page=".$i."&xu=".$xu."&type=".$type."&keys=".$keys."\">".$i."</a>"; 
} 
} 
if($page!=$pages){ 
$key.=" <a  href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."&xu=".$xu."&type=".$type."&keys=".$keys."\">下一页</a> ";//下一页 
$key.="<a href=\"".$_SERVER['PHP_SELF']."?type=".$type."&keys=".$keys."&xu=".$xu."&page={$pages}\">最后一页</a>"; //最后一页 
}else { 
$key.="下一页 ";//下一页 
$key.="最后一页"; //最后一页 
} 
$key.=''; 
?>    <div class="fr" id="page"><?php echo $key?></div>
        </div>
        </form>
    </div>
	<?php
	}
	?>
</body>
</html>

<script language="javascript" charset="utf-8">
function init(i) {
	var windowWidth, windowHeight;
	windowWidth=$(window).width();
	windowHeight=$(window).height();
	if(i==1){
		$("#k_btn1").hide();
		$("#k_btn2").show();
		$("#k_left").hide();
		$("#k_right").width(windowWidth-3);
	}
	else if(i==2){
		$("#k_btn2").hide();
		$("#k_btn1").show();
		$("#k_left").show();
		$("#k_right").width(windowWidth-193);
	}
	else {
		$("#k_left").height(windowHeight-158);
		$("#f_left").height(windowHeight-158);
		$("#k_btn1").css("top",(windowHeight-158-58)/2+"px");
		$("#k_btn2").css("top",(windowHeight-158-58)/2+"px");
		$("#k_right").width(windowWidth-193);
		$("#k_right").height(windowHeight-158);
		iFrame = $("#main");
		iFrame.height(windowHeight-158);
	}
}
$(document).ready(function() {
    init(0);
    window.onresize = function() {
        init(0);
    }
});
</script>